﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace Platform.Amazon {
    public class Market {

        private static Market[] _ls;

        public string Area;

        public string Country;

        public string Lang;

        public string Cur;

        public string PlaceId;

        public string Charset;

        public string Post;

        public string Url;

        public static Market[] List {
            get {
                return _ls;
            }
        }

        static Market() {
            List<Market> list = new List<Market>{
			        new Market("US", "美国", "en", "USD", "ATVPDKIKX0DER", "utf-8", "https://mws.amazonservices.com", "http://www.amazon.com/gp/product/"),
			        new Market("CA", "加拿大", "en", "CAD", "A2EUQ1WTGCTBG2", "utf-8", "https://mws.amazon.ca", "http://www.amazon.ca/gp/product/"),
			        new Market("MX", "墨西哥", "es", "MXN", "A1AM78C64UM0Y8", "utf-8", "https://mws.amazon.com", "http://www.amazon.com.mx/gp/product/"),
			        new Market("GB", "英国", "en", "GBP", "A1F83G8C2ARO7P", "utf-8", "https://mws.amazon.co.uk", "http://www.amazon.co.uk/gp/product/"),
			        new Market("FR", "法国", "fr", "EUR", "A13V1IB3VIYZZH", "utf-8", "https://mws.amazon.fr", "http://www.amazon.fr/gp/product/"),
			        new Market("DE", "德国", "de", "EUR", "A1PA6795UKMFR9", "utf-8", "https://mws.amazon.de", "http://www.amazon.de/gp/product/"),
			        new Market("IT", "意大利", "it", "EUR", "APJ6JRA9NG5V4", "utf-8", "https://mws.amazon.it", "http://www.amazon.it/gp/product/"),
			        new Market("ES", "西班牙", "es", "EUR", "A1RKKUPIHCS9HS", "utf-8", "https://mws.amazon.es", "http://www.amazon.es/gp/product/"),
			        new Market("AU", "澳大利亚", "en", "AUD", "A39IBJ37TRP1C6", "utf-8", "https://mws.amazon.com.au", "http://www.amazon.com.au/gp/product/"),
			        new Market("IN", "印度", "en", "INR", "A21TJRUUN4KGV", "utf-8", "https://mws.amazon.in", "http://www.amazon.in/gp/product/"),
			        new Market("JP", "日本", "ja", "JPY", "A1VC38T7YXB528", "shift-jis", "https://mws.amazon.jp", "http://www.amazon.jp/gp/product/"),
			        new Market("AE", "阿联酋", "en", "JPY", "A2VIGQ35RCS4UG", "utf-8", "https://mws.amazon.ae", "https://www.amazon.ae/dp/")
		        };
            _ls = list.ToArray();
        }

        public static Market Get(string abbr) {
            if (!string.IsNullOrEmpty(abbr)) {
                Market[] ls = _ls;
                int num = 0;
                Market Market;
                while (true) {
                    if (num >= ls.Length) {
                        return null;
                    }
                    Market = ls[num];
                    if (string.Compare(Market.Area, abbr, true) == 0) {
                        break;
                    }
                    num++;
                }
                return Market;
            }
            return null;
        }

        public static string GetCountry(string abbr) {
            Market Market = Get(abbr);
            return (Market == null) ? "" : Market.Country;
        }

        //public static Record ToRecord()
        //{
        //    Record record = new Record();
        //    for (int i = 0; i < _ls.Length; i++)
        //    {
        //        Market Market = _ls[i];
        //        record.AddRow();
        //        record.Columns.Add("id").Set(i + 1);
        //        record.Columns.Add("abbr").Set(Market.Area);
        //        record.Columns.Add("country").Set(Market.Country);
        //        record.Columns.Add("lang").Set(Market.Lang);
        //        record.Columns.Add("cur").Set(Market.Cur);
        //        record.Columns.Add("placeid").Set(Market.PlaceId);
        //        record.Columns.Add("post").Set(Market.Post);
        //    }
        //    record.MoveFirst();
        //    return record;
        //}

        private Market(string abbr, string country, string lang, string cur, string placeid, string charset, string post, string url) {
            Area = abbr;
            Country = country;
            Lang = lang;
            Cur = cur;
            PlaceId = placeid;
            Charset = charset;
            Post = post;
            Url = url;
        }
    }
}